import asyncio


def callback(sleep_times, loop):
    print("success time {}".format(sleep_times))


def stoploop(loop):
    loop.stop()


# call_later, call_at
if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    now = loop.time()
    # 第一个参数表示多少秒后执行
    loop.call_later(1, callback, 12, loop)
    loop.call_later(2, callback, 11, loop)
    # 时间需要使用time形式
    loop.call_at(now + 2, callback, 2, loop)
    loop.call_at(now + 1, callback, 1, loop)
    loop.call_at(now + 3, callback, 3, loop)
    # 在恰当的时候停止loop
    loop.call_at(now + 4, stoploop, loop)
    # 优先于上面call_at打印 
    loop.call_soon(callback, 4, loop)
    loop.run_forever()
